package com.fqgj.sentry.biz.rm;

import com.fqgj.sentry.biz.rm.vo.CurrentExecutorComboVo;
import com.fqgj.sentry.biz.rm.vo.EventComboVo;
import com.fqgj.sentry.manage.entity.McApplicationEntity;
import com.fqgj.sentry.manage.service.ApplicationService;
import com.fqgj.sentry.policy.client.EventService;
import com.fqgj.sentry.policy.client.PolicyExecutorService;
import com.fqgj.sentry.policy.client.PolicySetService;
import com.fqgj.sentry.policy.entity.PcEventEntity;
import com.fqgj.sentry.policy.entity.PcExecutorEntity;
import com.fqgj.sentry.policy.entity.PcPolicySetsEntity;
import com.fqgj.sentry.policy.enums.ExecutorTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ykpbean kangping.ying@yuntu-inc.com
 *
 * @description
 * @create 2017-08-17 上午10:14
 */

@Component
public class RiskTrendBusiness {
    @Autowired
    private ApplicationService applicationService;
    @Autowired
    private PolicySetService policySetService;
    @Autowired
    private EventService eventService;
    @Autowired
    private PolicyExecutorService policyExecutorService;

    public List<EventComboVo> getEventCombo(String appCode, Long merchantId) {
        McApplicationEntity applicationEntity = applicationService.selectByMerchantIdAndAppCode(merchantId, appCode);
        List<PcPolicySetsEntity> pcPolicySetsEntities = policySetService.selectList(applicationEntity.getId());
        List<EventComboVo> eventComboVoList = new ArrayList<>();
        for (PcPolicySetsEntity entity : pcPolicySetsEntities) {
            PcEventEntity pcEventEntity = eventService.selectEvent(entity.getEventId());
            EventComboVo eventComboVo = new EventComboVo();
            eventComboVo.setEventame(pcEventEntity.getName())
                    .setEventId(entity.getEventId())
                    .setPolicySetId(entity.getId());
            eventComboVoList.add(eventComboVo);
        }
        return eventComboVoList;
    }

    public List<CurrentExecutorComboVo> getCurrentExecutorCombo(Long policySetId) {
        List<PcExecutorEntity> pcExecutorEntityList = policyExecutorService.selectPcCurrentAllExecutor(policySetId);
        List<CurrentExecutorComboVo> currentExecutorComboVos = new ArrayList<>();

        for (PcExecutorEntity executorEntity : pcExecutorEntityList) {
            CurrentExecutorComboVo currentExecutorComboVo = new CurrentExecutorComboVo()
                    .setExecutorId(executorEntity.getId())
                    .setType(executorEntity.getType());
            if (executorEntity.getType().equals(ExecutorTypeEnum.challenger.getType())) {
                currentExecutorComboVo.setTypeName(ExecutorTypeEnum.challenger.getDesc());
            }
            if (executorEntity.getType().equals(ExecutorTypeEnum.champion.getType())) {
                currentExecutorComboVo.setTypeName(ExecutorTypeEnum.champion.getDesc());
            }
            if (executorEntity.getType().equals(ExecutorTypeEnum.verifier.getType())) {
                currentExecutorComboVo.setTypeName(ExecutorTypeEnum.verifier.getDesc());
            }
            currentExecutorComboVos.add(currentExecutorComboVo);
        }
        return currentExecutorComboVos;
    }
}
